/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.finance;

import cn.ekuma.data.ui.swing.SwingEditorRecord;
import cn.ekuma.epos.module.ERP_UI_Swing_Model;
import cn.ekuma.rabbit.spi.I_ModelPart;

import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.SerializerReadBasic;
import com.openbravo.data.loader.StaticSentence;
import com.openbravo.data.user.I_SaveProvider;
import com.openbravo.data.user.I_ListProvider;
import com.openbravo.data.user.ListProviderCreator;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.base.AppView;
import com.openbravo.pos.panels.JPanelTable;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 *
 * @author Administrator
 */
public class JCashBookPanel extends JPanelTable implements I_ModelPart<ERP_UI_Swing_Model>{
    JCashBookEditor  editor;
    I_ListProvider   listProvider;

    @Override
    public void init() {
        editor=new JCashBookEditor ();
        editor.init((AppView) app,this,mode.getDLSystem(), mode.getDLSales());
        listProvider=new ListProviderCreator(new StaticSentence(mode.getManager().getSession()
            , "SELECT HOST, HOSTSEQUENCE, DATESTART, DATEEND,NAME,MONEY  FROM CLOSEDCASH WHERE DATEEND IS NULL "
            , null
            , new SerializerReadBasic(new Datas[] {Datas.STRING, Datas.INT, Datas.TIMESTAMP, Datas.TIMESTAMP, Datas.STRING,Datas.STRING})));
    }

    @Override
    public SwingEditorRecord getEditor() {
        return editor;
    }

    @Override
    public I_ListProvider getListProvider() {
      return  listProvider;
    }

    @Override
    public I_SaveProvider getSaveProvider() {
        return null;
    }

    @Override
    public String getTitle() {
       return AppLocal.getIntString("Menu.CashBook");
    }

    @Override
    public ListCellRenderer getListCellRenderer() {
        return new DefaultListCellRenderer() {

            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, null, index, isSelected, cellHasFocus);
                Object[] values = (Object[]) value;
                setText((String)values[0]+"/"+(String) values[4]); // Un espacio en caso de nulo para que no deja la celda chiquitita.
                return this;
            }
        };
    }

	@Override
	public String getModelName() {
		return ERP_UI_Swing_Model.MODEL_NAME;
	}

	
	ERP_UI_Swing_Model mode;
	@Override
	public void setModel(ERP_UI_Swing_Model mode) {
		this.mode=mode;
		
	}

}
